﻿@{
    ViewBag.Title = "Index";
}
@section Head
{
       @Html.Css("EditForm", "RightSeparateModule", "dp")
       @Html.Js("datepicker")
    <script src="../../Scripts/datepicker-zh.js" type="text/javascript"></script>
       <script type="text/javascript">
           var maiheight = document.documentElement.clientHeight;
           var mainWidth = document.documentElement.clientWidth; // 减去左边的宽度
           var value_in = "";
           $(document).ready(function () {
               $("#instockDt").datepicker({ dateFormat: 'yy-mm-dd' });
               var otherpm = $("#title").height() + $("#findDiv").height(); // 290;
               var gh = maiheight - otherpm - 80;
               var options = {
                   height: gh,
                   width: mainWidth,
                   url: '@Url.Action("GetDetailList")',
                   colModel: [
                    { display: '编号', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                    { display: '入库日期', name: 'AppDt', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '物品名称', name: 'Goods_ID', width: 120, sortable: false, hide: false, align: 'left' },
                      { display: '物品类型', name: 'SpType', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '数量', name: 'Count', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '使用人', name: 'UserMan', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '备注', name: 'Remark', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '记录日期', name: 'RecordDateTime', width: 100, sortable: false, hide: true, align: 'left' },
                    { display: '操作人', name: 'OperatorID', width: 80, sortable: false, hide: true, align: 'left' },
                    { display: '订单编号', name: 'OrderNo', width: 80, sortable: false, hide: true, align: 'left' }
			      	],
                   buttons: [
                            { name: 'Add', displayname: "新建", title: "新建", bclass: 'add', onpress: toolbarItem_onclick },
                            { name: 'Edit', displayname: "修改", title: "编辑", bclass: 'edit', onpress: toolbarItem_onclick },
                            { name: 'Delete', displayname: "删除", title: "删除", bclass: 'delete', onpress: toolbarItem_onclick },
                            { separator: true }
                         ],
                   singleselected: true,
                   title: false,
                   usepager: true,
                   page: 1,
                   rp: 20,
                   rpOptions: [10, 15,20],
                   showcheckbox: true,
                   rowbinddata: true,
                   singleselected: false //是否单选
               };

               $("#SundriesTable_T").flexigrid(options);

               $("#btnQueryList").bind("click", function () {
                   refreshbyclick();
               });
               //新增，删除，修改
               function toolbarItem_onclick(cmd, grid) {
                   if (cmd == "Add") {
                       OpenModelWindow('@Url.Action("Add")',
                        {
                            width: 764,
                            height: 487,
                            caption: "新增物品进货申领",
                            onclose: refresh
                        }
                       );
                   }
                   else if (cmd == 'Edit') {
                       var ids = "";
                       if ($('.trSelected', grid).length == 0 || $('.trSelected', grid).length > 1) {
                           showLoadingMsg("请选择一行数据进行编辑", { left: 300, top: 2 }, true, 3000);
                           return false;
                       }
                       else {
                           var items = $('.trSelected', grid);
                           for (i = 0; i < items.length; i++) {
                               if (i == items.length - 1) {
                                   ids += items[i].id.substr(3);
                               } else {
                                   ids += items[i].id.substr(3) + ", ";
                               } //if 
                           } //for
                       }
                       OpenModelWindow('@Url.Action("Add")?id=' + ids,
                        {
                            width: 764,
                            height: 484,
                            caption: "维护零星物品进货",
                            onclose: refresh
                        });
                   }
                   else if (cmd == 'Delete') {
                       if ($('.trSelected', grid).length == 0) {
                           showLoadingMsg("请选择要删除的行", { left: 300, top: 2 }, true, 3000);
                           return false;
                       } else {
                           if (confirm("确定要删除吗?")) {
                               var ids = "";
                               var items = $('.trSelected', grid);
                               for (i = 0; i < items.length; i++) {
                                   if (i == items.length - 1) {
                                       ids += items[i].id.substr(3);
                                   } else {
                                       ids += items[i].id.substr(3) + ", ";
                                   } //if 
                               } //for
                               $.ajax({
                                   url: '@Url.Action("Delete")',
                                   type: "POST",
                                   data: { id: ids },
                                   success: function (callback) {
                                       if (callback) {
                                           refresh();
                                       }
                                   },
                                   error: function () {
                                   }
                               });
                           }

                       }
                   }
               } // end of toolbarItem_onclick
               function refreshbyclick() {
                   var idt = ($("#instockDt").val() == null) ? "" : $("#instockDt").val();
                   var iname = ($("#Con_GoodsInfoId").val() == null) ? "" : $("#Con_GoodsInfoId").val();
                   if ($("#Con_GoodsInfoGoodsName").val() == "") {
                       iname = "";
                   }
                   options.query = "and ((AppDt = '" + idt + "') or ('" + idt + "'='')) and ((Goods_ID = '"
                            + iname + "') or ('" + iname + "'=''))";
                   options.newp = 0;
                   $("#SundriesTable_T").flexOptions(options).flexReload();
               }
               function refresh() {
                   options.query = "and OrderNo = '" + $("#orderno").val() + "'";
                   options.newp = 0;
                   $("#SundriesTable_T").flexOptions(options).flexReload();
               }
               $("#btnExport").click(function () {
                   var dt = $("#instockDt").val();
                   var gid = $("#Con_GoodsInfoId").val();
                   var strulr = "Exprot?time=" + dt + "&name=" + gid;
                   var subwin = window.open(strulr, "", "menubar=no,toolbar=no,status=no,resizable=no,scrollbars=yes");
                   subwin.moveTo(0, 0);
                   subwin.resizeTo(window.screen.availWidth, window.screen.availHeight);
                   return false;
               });
           });      
       </script>
}
       <div id="container">
        <div id="mainContent">
            <div id="title" class="title">物品申请管理</div>
            <div id="findDiv">
            @Html.Hidden("orderno")
             <table>
                <tr>
                 <td >入库日期：</td>
                 <td>@Html.TextBox("instockDt", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })</td>
                 <td>&nbsp;&nbsp;&nbsp;物品名称:  </td>
                 <td> @Html.Partial("RtnSporadicList")
                 </td>                     
                 <td><a id="btnQueryList" class="button" href="javascript:void(0);"><span>查 询</span></a>    <a id="btnExport" class="button" href="javascript:void(0);"><span>导 出</span></a>
                 </td>
                </tr>
             </table>
            </div>
            <table id="SundriesTable_T" style="display: none;">
            </table>
        </div>
    </div>
